<?php

/**
 * RatingController
 * 
 * @ Konovalov Maxim aka ZloY	max.zloy@gmail.com
 * 
 */
class RatingController extends Zend_Controller_Action {
	protected $_item;	
	protected $_itemType;
	protected $_itemId;
	
	public function init()
	{
		$this->_itemType = $this->_getParam('item_type', null);
		$this->_itemId = (int) $this->_getParam('item_id',0);
		$this->_item = Model_Rating::createItem($this->_itemId, $this->_itemType);
	}
	
	public function indexAction() {
	
	}
	
	public function setAction(){
		$mark = $this->_getParam('mark');
		$this->_item->setRating($mark);
		if($this->getRequest()->isXmlHttpRequest()){
			Zend_Layout::getMvcInstance()->disableLayout();
			$this->view->item = $this->_item;
			$this->view->item_id = $this->_itemId;
			$this->view->item_type = $this->_itemType;
		} else {
			$this->_redirect($_SERVER['HTTP_REFERER']);
		}
		
	}
}